/*
 * @Description: 行业选择
 * @Author: iamsmiling
 * @Date: 2021-06-07 08:29:34
 * @LastEditTime: 2021-06-13 18:09:20
 */
import 'dart:ui';

import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/domain/remote/industry/industry_entity.dart';
import 'package:credit_business_circle/pages/industry/industry_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class IndustryPage extends GetView<IndustryController> {
  const IndustryPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("所属行业"),
        elevation: 0,
      ),
      body: GetBuilder<IndustryController>(
          init: IndustryController(),
          builder: (_) {
            return Column(
              children: [
                Container(
                  padding: EdgeInsets.only(left: R.dimen.dp16),
                  width: R.dimen.width,
                  height: R.dimen.dp68,
                  alignment: Alignment.centerLeft,
                  color: R.color.ffffffff,
                  child: Text(
                    "请选择所属行业",
                    style: TextStyle(
                        color: R.color.ff323232,
                        fontSize: R.dimen.sp16,
                        fontWeight: FontWeight.w600),
                  ),
                ),
                Expanded(
                    child: Row(
                  children: [
                    Expanded(
                        flex: 1,
                        child: Container(
                          child: ListView.builder(
                              itemCount: _.list.length,
                              itemBuilder: (BuildContext context, int i) {
                                IndustryEntity item = _.list[i];
                                return GestureDetector(
                                  onTap: () => _.selectParent(i),
                                  child: Container(
                                    color: item == _.list[_.currentIndex]
                                        ? R.color.fff5f5f5
                                        : R.color.ffffffff,
                                    padding: EdgeInsets.only(
                                        left: R.dimen.dp18,
                                        top: R.dimen.dp16,
                                        bottom: R.dimen.dp16),
                                    child: Text(
                                      item.name,
                                      style: item != _.list[_.currentIndex]
                                          ? TextStyle(
                                              fontSize: R.dimen.sp13,
                                              color: R.color.ff555555)
                                          : TextStyle(
                                              color: R.color.ff36ba93,
                                              fontSize: R.dimen.sp13,
                                              fontWeight: FontWeight.w600),
                                    ),
                                  ),
                                );
                              }),
                        )),
                    Expanded(
                        flex: 2,
                        child: Container(
                          margin: EdgeInsets.only(left: R.dimen.dp32),
                          child: ListView.builder(
                              itemCount: _.list[_.currentIndex].children.length,
                              itemBuilder: (BuildContext context, int i) {
                                IndustryEntity e =
                                    _.list[_.currentIndex].children[i];
                                return GestureDetector(
                                  onTap: () => _.selectChild(i),
                                  child: Container(
                                    padding: EdgeInsets.only(
                                        top: R.dimen.dp16,
                                        bottom: R.dimen.dp16),
                                    child: Text(
                                      e.name,
                                      style: e !=
                                              _.list[_.currentIndex]
                                                  .children[_.currentChildIndex]
                                          ? TextStyle(
                                              fontSize: R.dimen.sp13,
                                              color: R.color.ff555555)
                                          : TextStyle(
                                              color: R.color.ff36ba93,
                                              fontSize: R.dimen.sp13,
                                              fontWeight: FontWeight.w600),
                                    ),
                                  ),
                                );
                              }),
                        )),
                  ],
                ))
              ],
            );
          }),
      bottomNavigationBar: Container(
        color: R.color.ffffffff,
        padding: EdgeInsets.only(
            left: R.dimen.dp20,
            right: R.dimen.dp20,
            top: R.dimen.dp14,
            bottom: MediaQuery.of(context).padding.bottom + R.dimen.dp14),
        child: Row(
          children: [
            Expanded(
                flex: 1,
                child: Container(
                  margin: EdgeInsets.only(right: R.dimen.dp12),
                  child: MaterialButton(
                    onPressed: Get.back,
                    color: R.color.fff5f5f5,
                    textColor: R.color.ff777777,
                    elevation: 0,
                    padding: EdgeInsets.symmetric(vertical: R.dimen.dp13),
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(R.dimen.sp5)),
                    child: Text(
                      "取消",
                      style: TextStyle(fontSize: R.dimen.sp14),
                    ),
                  ),
                )),
            Expanded(
                flex: 2,
                child: ElevatedButton(
                    style: ButtonStyle(
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(R.dimen.sp5))),
                    ),
                    onPressed: () => Get.back(
                        result: IndustryEntity(
                            name:
                                controller.list[controller.currentIndex].name)),
                    child: Text("确定")))
          ],
        ),
      ),
    );
  }
}
